﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EasyClass {
	public partial class EditLimitForm : Form {
		Controller controller;
		private HashSet<string> limit;

		public EditLimitForm(Controller c) {
			InitializeComponent();

			controller = c;
			limit = c.GetLimit();
			FreshLimitTextBox();
		}

		public void FreshLimitTextBox() {
			listBox1.Items.Clear();
			foreach (string studentID in limit)
				listBox1.Items.Add(studentID);
		}

		private void button3_Click(object sender, EventArgs e) {
			controller.SetLimit(limit);
			Close();
		}

		private void button1_Click(object sender, EventArgs e) {
			string s = textBox1.Text;
			string[] ss = s.Split(new char[]{'\r', '\n', ' '});
			foreach (string studentID in ss) {
				if (studentID.Length > 0 && !limit.Contains(studentID)) limit.Add(studentID);
			}
			FreshLimitTextBox();
			textBox1.Clear();
		}

		private void button2_Click(object sender, EventArgs e) {
			for (int i = 0; i < listBox1.SelectedItems.Count; ++i)
				limit.Remove(listBox1.SelectedItems[i].ToString());
			FreshLimitTextBox();
		}

		private void EditLimitForm_Load(object sender, EventArgs e) {

		}
	}
}
